<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p id="demo">获取你的地理位置：</p>
<button onclick="getLocation()">点一下</button>
<script>
    var demo=document.getElementById("demo");
    function getLocation() {
        if(navigator.geolocation){
            navigator.geolocation.getCurrentPosition(showPosition);
        }else{
            demo.innerHTML="该浏览器不支持获取地理位置。";
        }
    }
    function showPosition(position) {
        demo.innerHTML="纬度："+position.coords.latitude+"<br/>经度："+position.coords.longitude;
    }
</script>

</body>
</html>